import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import setupExtend from 'vite-plugin-vue-setup-extend'

// const lifecyclePlugin = {
//   name: 'vue-lifecycle-monitor',
//   transform(code:any, id:any) {
   
//     if (id.endsWith('.vue') && !id.includes('node_modules')
//       && id.includes("/pages/application")
//       && !id.includes("/pages/application/application.vue")
//     ) {
//       let newCode = 
//         `
//         import { onMounted, onUnmounted } from 'vue'
//         onMounted(() => console.log('全局挂载'))
//         onUnmounted(() => console.log('全局卸载'))
//         ` + code
//       console.log(newCode)  
//       return newCode
//     }
//   }
// }

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // vueDevTools(),
    setupExtend(),
    // lifecyclePlugin,
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  base: '/simple-server/web/',
  server:{
    port: 5175,
    proxy:{
      '^/simple-server/api/.*': {
        changeOrigin: true,
        target: 'http://127.0.0.1:30001',
      },
      '^/simple-server/ws/.*': {
        changeOrigin: true,
        target: 'ws://127.0.0.1:30001',
      }
    }
  }
})
